package utility;

public class Pagination {
	private int currentPage;
	private int limitRecord;
	private int totalRecord;

	public Pagination(int currentPage, int limitRecord, int totalRecord) {
		super();
		this.currentPage = currentPage;
		this.limitRecord = limitRecord;
		this.totalRecord = totalRecord;
	}

	public Pagination() {
		this(1, 2, 0);
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public void setLimitRecord(int limitRecord) {
		if (limitRecord > 50)
			limitRecord = 50;
		this.limitRecord = limitRecord;
	}

	public int getLimitRecord() {
		return limitRecord;
	}

	public int getTotalPage() {
		return (int) Math.ceil((double) this.getTotalRecord()
				/ this.getLimitRecord());
	}

	public int getNextPage() {
		return this.getCurrentPage() + 1;
	}

	public int getPreviousPage() {
		return this.getCurrentPage() - 1;
	}

	public int getOffset() {
		return (this.getCurrentPage() - 1) * this.getLimitRecord();
	}

	public boolean hasNextPage() {
		return this.getCurrentPage() < this.getTotalPage();
	}

	public boolean hasPreviousPage() {
		return this.getCurrentPage() > 1;
	}

}
